package com.sunshine.lnuplus.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import com.sunshine.lnuplus.R
import com.sunshine.lnuplus.model.ScoreData
import com.sunshine.lnuplus.utils.ColorUtils
import com.sunshine.lnuplus.view.ScrollTextView

/**
 * Created by sunshine on 2020/3/13
 */

class ScoreRecyclerAdapter(private val context: Context) : RecyclerView.Adapter<ScoreRecyclerAdapter.ScoreRecyclerViewHolder>() {

    private val colorUtils = ColorUtils

    init {
        colorUtils.init(context)
    }

    class ScoreRecyclerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val cardView = itemView.findViewById<CardView>(R.id.score_cardview)
        val lessonName = itemView.findViewById<ScrollTextView>(R.id.lesson_name)
        val score = itemView.findViewById<TextView>(R.id.score)
        val info = itemView.findViewById<TextView>(R.id.info)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ScoreRecyclerViewHolder {
        return ScoreRecyclerViewHolder(
            LayoutInflater.from(context).inflate(
                R.layout.item_score,
                parent,
                false))
    }

    override fun getItemCount(): Int {
        return ScoreData.scoreList!!.size
    }

    override fun onBindViewHolder(holder: ScoreRecyclerViewHolder, position: Int) {
        holder.cardView.setCardBackgroundColor(colorUtils.setBackgroundColor(ScoreData.scoreList!![position].lessonName))
        holder.lessonName.text = ScoreData.scoreList!![position].lessonName
        holder.score.text = ScoreData.scoreList!![position].score
        holder.info.text = "学分：${ScoreData.scoreList!![position].lessonScore}   课程类别：${ScoreData.scoreList!![position].info}"
    }
}